from django.contrib.auth.models import AbstractUser
from django.db import models
from utils.common_models import BaseModel


# Create your models here.
class User(AbstractUser):
    mobile = models.CharField(max_length=11, unique=True)
    # 需要pillow包的支持
    icon = models.ImageField(upload_to='icon', default='icon/default.png')

    class Meta:
        db_table = 'luffy_user'  # 指定表名
        verbose_name = '用户表'  # 后台管理看到的中文
        verbose_name_plural = verbose_name

    def __str__(self):  # 打印对象，显示的
        return self.username


class ClientType(BaseModel):
    """
    客户端类型
    """
    bw = models.TextField(verbose_name='浏览器名称')
    ip = models.CharField(verbose_name='ip', max_length=64)
    url = models.CharField(verbose_name='url', max_length=64)
    user = models.ForeignKey(verbose_name='用户', to='User', db_constraint=False, on_delete=models.DO_NOTHING,
                             null=True,
                             blank=True)

    class Meta:
        db_table = 'luffy_client_type'  # 指定表名
        verbose_name = '客户端类型'  # 后台管理看到的中文
        verbose_name_plural = verbose_name

    def __str__(self):  # 打印对象，显示的
        return self.bw


class UserPassword(BaseModel):
    """
    密码
    """
    user = models.ForeignKey(verbose_name='用户', to='User', db_constraint=False, on_delete=models.DO_NOTHING,
                             null=True,
                             blank=True)
    password = models.CharField(verbose_name='密码', max_length=225)

    class Meta:
        db_table = 'luffy_user_passworde'  # 指定表名
        verbose_name = '客户端类型'  # 后台管理看到的中文
        verbose_name_plural = verbose_name

    def __str__(self):  # 打印对象，显示的
        return self.user.username
